import 'package:common/common.dart';
import 'package:get/get.dart';

import '../global_web/global_web_page.dart';
import 'app_router.dart';
import 'ext_get_navigation.dart';

class SchemRouter {
  static const schem = '/aiyou://shop/details?store_id=1';

/*
   web格式:        aiyou://web?url=https://www.baidu.com?title=标题
  页面提示内容:     aiyou://page/tips?title=AI植发&content=告别大脑门，植发拯救发际线！敬请期待！
  店铺分类列表:     aiyou://shop/category/page?category_id=15&title=AI试妆
  订单详情:        aiyou://order/details?order_id=4934358982596401371
  店铺详情:        aiyou://shop/details?store_id=1
  项目详情:        aiyou://package/details?package_id=1&artisan_id=1   // package_id 为必填项  artisan_id为选填项
  艺人详情:        aiyou://artisan/details?artisan_id=1
*/

  //  页面格式:  aiyou://shop/list?type=9
  //  web格式:  aiyou://web?url=https://www.baidu.com?type=1&id=8
  //  aiyou://shop/category/page?category_id=1&title=女装
  static void openSchem({required String schem, String title = '', LaunchModel launchModel = LaunchModel.standard}) {
    if (schem.isEmpty) {
      return;
    }

    if (!schem.startsWith('aiyou://')) {
      return;
    }

    Uri uri = Uri.parse(schem);

    String authority = uri.authority;
    String route = uri.authority + uri.path;
    Map<String, dynamic> queryParameters = uri.queryParameters;

    // 跳转网页
    if (CommonRouter.web.contains(route)) {
      String tit = queryParameters['title'] ?? title;
      GlobalWebPage.startInstance(tit, queryParameters['url']);
    } else {
      // 跳转页面
      Get.pushPage(route, arguments: queryParameters, launchModel: launchModel);
    }
    logs(
        "\n"
        "\nschem =    $schem"
        "\nuri   =    $uri"
        "\nauthority =  $authority"
        "\npath =  ${uri.path}"
        "\nroute =   $route "
        "\nparameters =   $queryParameters",
        tag: "schem",
        line: true);
  }
}
